import { Extension } from '@tiptap/core'

export interface CustomExtensionOptions {
  types: string[],
  color: string|null
}

/* declare module '@tiptap/core' {
  interface Commands<ReturnType> {
  }
} */

export const CustomExtension = Extension.create<CustomExtensionOptions>({
  name: 'customExtension',
  addOptions() {
    return {
      types: [],
      color: null
    }
  },
  addGlobalAttributes() {
    return [
      {
        types: this.options.types,
        attributes: {
          custom: {
            parseHTML: element => {
              const color = element.style.color
              return color ? color.replace(/['"]+/g, '') : null
            },
            renderHTML: attributes => {
              return { style: `color: ${attributes.color}` }
            },
          },
        },
      },
    ]
  },
  addCommands() {
    return {
    }
  },

  addKeyboardShortcuts() {
    return {
    }
  },
})

export default CustomExtension